<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const url = 'http://www.liulongbin.top:3006/api/news';

        // resolve相当于.then  reject相当于catch
        // 原生封装axios
        function axios(conf) {
            return new Promise((resolve, reject) => {
                // 1.
                const xhr = new XMLHttpRequest();
                // 2.
                xhr.open(conf.method, conf.url);
                // 3.
                xhr.send();
                // 4.
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        resolve(JSON.parse(xhr.responseText));
                    }
                };
            });
        }

        (async () => {
            const res = await axios({
                method: 'get',
                url,
            });
            console.log(res);

            const res1 = await axios({
                method: 'get',
                url,
            });
            console.log(res1);


            const res2 = await axios({
                method: 'get',
                url,
            });
            console.log(res2);
        })();
    </script>
</body>
</html>